package controller;

import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheManager;

import com.google.appengine.api.memcache.jsr107cache.GCacheFactory;

import service.PageRankService;

public class PutCache {
	@SuppressWarnings("unchecked")
	public static String Pr(String nameCache)
	{
		String pr = "0";
		Cache cache=null;
		
		Map props = new HashMap();
        props.put(GCacheFactory.EXPIRATION_DELTA, 3000000);
		
    	try {
		    cache = CacheManager.getInstance().getCacheFactory().createCache(props);
		} catch (CacheException e) {
		   e.printStackTrace();
		}
		
    	if(cache.containsKey(nameCache))
		{
			pr = (String)cache.get(nameCache);
		} else {
			PageRankService prService = new PageRankService();
			
			pr = prService.getPR(nameCache);
			
			cache.put(nameCache, pr);
		}
    	
    	return pr;
	}
}
